/**
 * @file kernel.h
 * @brief System Service Interface
 *
 * This module supplies the common service interface
 * to the whole system
 *
 * @author yemt@witsi.cn
 * @date 2011-08-04
 * @version rxSys.kernel.03
 */
#ifndef KERNEL_H_
#define KERNEL_H_

#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>

/************************************************************************
 * Security Service
 ************************************************************************/
void security_status_clear(void);
uint32_t security_status(void);
void security_enable(void *mode);
void security_disable(void);
uint8_t get_power_status(void);



/************************************************************************
 * Nvsram Service
 ************************************************************************/
int _nv_write(uint32_t offset, uint8_t * buf, int buflen);
int _nv_read(uint32_t offset, uint8_t * buf, int buflen);
void _nv_clear(uint32_t offset,  uint32_t size);


/************************************************************************
 * Time Service
 ************************************************************************/
uint32_t get_sys_timer(void);           /**< Get System Timer Current Value */
uint32_t timeout_start(void);           /**< Start a Timeout Procedure */
uint32_t timeout_test(uint32_t *start, uint32_t *ms); /**< Test Whether the Timeout has Occurred */
void udelay(uint32_t us);               /**< Delay Microseconds */
void mdelay(uint32_t ms);               /**< Delay Milliseconds */

/* Misc Device */
void reset(void);

/************************************************************************
 * File System Interface
 ************************************************************************/
typedef int (*fs_format_t)(void);
/**
 * File System Entry
 * Each type file system should implement these interface
 */
typedef struct {
        const char * name;                                              /**< The File System Name */

        int (*open)(const char *name, int flags, ...);                  /**< Open a File */
        int (*close)(int fd);                                           /**< Close a File */
        ssize_t (*read)(int fd, void* buffer, size_t size);             /**< Read from a File */
        ssize_t (*write)(int fd, const void* buffer, size_t size);      /**< Write to File */
        int (*poll)(int fd, uint32_t flags);                            /**< Poll Status from a File */
        int (*ioctl)(int fd, uint32_t cmd, void *arg);                  /**< Control to a File */
        off_t (*lseek)(int fd, off_t offset, int whence);               /**< Seek to a File */
		int (*truncate)(int fd,off_t length);
		int (*unlink)(const char * name);
}file_sys_t;
void fs_register(const file_sys_t *fs, fs_format_t format);

#define SYS_VERSION     "RxSys_V2.2.4"              /* rxSys Version */
const char * get_kernel_version(char *buf, int max);

#endif /* KERNEL_H_ */
